//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>

int __cdecl wcsncmp(const wchar_t* pStr1, const wchar_t* pStr2, size_t count)
{
/*
    register int __res;
#if !defined(_arm)
    int d0, d1, d2;
    asm __volatile__(
        "1:\tdecl %3\n\t"
        "js 2f\n\t"
        "lodsw\n\t"
        "scasw\n\t"
        "jne 3f\n\t"
        "testw %%ax,%%ax\n\t"
        "jne 1b\n"
        "2:\txorl %%eax,%%eax\n\t"
        "jmp 4f\n"
        "3:\tsbbl %%eax,%%eax\n\t"
        "orw $1,%%ax\n"
        "4:"
         :"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
         :"1" (pStr1),"2" (pStr2),"3" (count));
#else
    asm __volatile__(
        "cmp r2, #0\n\t"
        "beq 3f\n\t"
        "1:\tldrh r3, [r0], #2\n\t"
        "ldrh r4, [r1], #2\n\t"
        "sub r5, r3, r4\n\t"
        "cmp r5, #0\n\t"
        "bne 2f\n\t"
        "sub r2, r2, #1\n\t"
        "cmp r2, #0\n\t"
        "ble 2f\n\t"
        "mov r4, r4, lsl #16\n\t"
        "mov r4, r4, lsr #16\n\t"
        "cmp r4, #0\n\t"
        "bne 1b\n"
        "2:\tmov %0, r5\n\t"
        "b 4f\n"
        "3:\tmov %0, #0\n"
        "4:\n"
        :"=r"(__res)
        ::"r5", "r3", "r4");
#endif

    return __res;
*/
    if (!count)
        return 0;

    while (--count && *pStr1 && *pStr1 == *pStr2) {
        pStr1++;
        pStr2++;
    }

    return *pStr1 - *pStr2;
}
